function(require, module, exports, window, document, frames, self, location, navigator, localStorage, history, Caches, screen, alert, confirm, prompt, XMLHttpRequest, WebSocket, Reporter, webkit, WeixinJSCore) {
    "use strict";
    function e(e, t) {
        if (! (e instanceof t)) throw new TypeError("Cannot call a class as a function")
    }
    var t = function() {
        function e(e, t) {
            for (var n = 0; n < t.length; n++) {
                var i = t[n];
                i.enumerable = i.enumerable || !1,
                i.configurable = !0,
                "value" in i && (i.writable = !0),
                Object.defineProperty(e, i.key, i)
            }
        }
        return function(t, n, i) {
            return n && e(t.prototype, n),
            i && e(t, i),
            t
        }
    } (),
    n = require("./config.js"),
    i = require("./http-config"),
    r = require("./http"),
    o = new(require("./log").Log),
    a = new r.Http,
    u = require("./md5"),
    s = function() {
        function r() {
            e(this, r),
            this.baseURL = n.Config.baseURL,
            this.retryTime = n.Config.retryTime,
            this.version = n.Config.version,
            this.cosFilePathPrefix = n.Config.cosFilePathPrefix,
            this.getFileTime = 0,
            this.authKey = n.Config.authKey
        }
        return t(r, [{
            key: "getFileContent",
            value: function(e, t, n) {
                var i = this;
                return new Promise(function(r, a) {
                    wx.downloadFile({
                        url: e + "?sign=" + t + "&t=" + n,
                        success: function(t) {
                            wx.getFileSystemManager().readFile({
                                filePath: t.tempFilePath,
                                encoding: "utf-8",
                                success: function(e) {
                                    r(e)
                                },
                                fail: function(t) {
                                    if (o.error("readFile", t), i.getFileTime++, !(i.getFileTime >= i.retryTime)) {
                                        var n = (new Date).getTime(),
                                        a = u.hex_md5(i.authKey + e + n);
                                        return i.getFileContent(e, a, n)
                                    }
                                    r("fail")
                                }
                            })
                        },
                        fail: function(e) {
                            o.error("downloadFile", e),
                            r("fail")
                        }
                    })
                })
            }
        },
        {
            key: "getCDNFile",
            value: function(e) {
                var t = this,
                n = t.cosFilePathPrefix + e,
                i = t.getFileToken(e).sign,
                r = t.getFileToken(e).timestamp;
                return new Promise(function(e, o) {
                    t.getFileContent(n, i, r).then(function(t) {
                        e(t)
                    })
                })
            }
        },
        {
            key: "getFileToken",
            value: function(e) {
                var t = parseInt((new Date).getTime() / 1e3);
                return {
                    sign: u.hex_md5(this.authKey + e + t),
                    timestamp: t
                }
            }
        },
        {
            key: "getReqResult",
            value: function(e, t) {
                var n = this,
                r = getApp().globalData,
                u = (new Date).getTime(),
                s = r.token,
                l = r.expiresIn,
                f = (r.reExpiresIn, r.reNewToken),
                g = i.Httpconfig.requestList[e].path,
                c = i.Httpconfig.requestList[e].data,
                h = i.Httpconfig.requestList[e].method,
                m = i.Httpconfig.requestList[e].version;
                if (t) {
                    var p = 0;
                    for (var v in c) c[v] = t[p],
                    p++
                }
                if (s && u > l - 6e5 && a.post(i.Httpconfig.requestList.getValidToken.version, n.buildUrl(i.Httpconfig.requestList.getValidToken.path), {
                    a: f
                }).then(function(e) {
                    "000000" == e.code ? (r.token = e.a, r.expiresIn = (new Date).getTime() + e.b, r.reExpiresIn = (new Date).getTime() + 2 * e.b, r.reNewToken = e.c) : o.error("getValidToken", e.msg)
                }), "POST" == h) {
                    var d = n.buildUrl(g);
                    return new Promise(function(e, t) {
                        a.post(m, d, c).then(function(t) {
                            e(t)
                        })
                    })
                }
                if ("GET" == h) {
                    var T = n.buildUrl(g, c);
                    return new Promise(function(e, t) {
                        a.post(m, T).then(function(t) {
                            e(t)
                        })
                    })
                }
            }
        },
        {
            key: "buildUrl",
            value: function(e, t) {
                var n = "",
                i = this.baseURL + e;
                if (!t) return i;
                var r = !0,
                o = !1,
                a = void 0;
                try {
                    for (var u, s = Object.keys(t)[Symbol.iterator](); ! (r = (u = s.next()).done); r = !0) {
                        var l = u.value;
                        n += l + "=" + t[l] + "&"
                    }
                } catch(e) {
                    o = !0,
                    a = e
                } finally {
                    try { ! r && s.
                        return && s.
                        return ()
                    } finally {
                        if (o) throw a
                    }
                }
                return n = "?" + n.substring(0, n.length - 1),
                i + n
            }
        },
        {
            key: "getValidToken",
            value: function(e) {
                var t = this,
                n = [e];
                return new Promise(function(e) {
                    t.getReqResult("getValidToken", n).then(function(t) {
                        "000000" == t.code ? (globalData.token = t.a, globalData.expiresIn = (new Date).getTime() + t.b, globalData.reExpiresIn = (new Date).getTime() + 2 * t.b, globalData.reNewToken = t.c, e(t)) : o.error("getValidToken", t.msg)
                    })
                })
            }
        }]),
        r
    } ();
    module.exports = {
        Base: s
    };
}